package com.usian.three.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * 文件名: AlidayuUtils
 * 创建者:
 * 创建时间:2022/5/24 18:47
 * 描述: 这是短信发送服务
 */
public class AlidayuUtils {
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = AlidayuUtils.createClient("LTAIlzwM0t5b0i4r", "moYvfwB0g0xQLygciSMjXPYQDXapnj");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("19834766820")
                .setSignName("")
                .setTemplateParam("测试专用");
        RuntimeOptions runtime = new RuntimeOptions();
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse =  client.sendSmsWithOptions(sendSmsRequest, runtime);
        System.out.println(sendSmsResponse.getBody().getCode()+"::"+sendSmsResponse.getBody().getMessage());
    }

    /**
     * 发送登录的验证码
     * @param phone 手机号
     * @param code 验证码
     * @return 发送标识
     */
    public String goToLogin(String phone,String code) throws Exception {

                com.aliyun.dysmsapi20170525.Client client = AlidayuUtils.createClient("LTAIlzwM0t5b0i4r", "moYvfwB0g0xQLygciSMjXPYQDXapnj");
                SendSmsRequest sendSmsRequest = new SendSmsRequest()
                        .setPhoneNumbers(phone)
                        .setSignName("")
                        .setTemplateParam("测试专用");
                RuntimeOptions runtime = new RuntimeOptions();
                // 复制代码运行请自行打印 API 的返回值
                SendSmsResponse sendSmsResponse =  client.sendSmsWithOptions(sendSmsRequest, runtime);
                return sendSmsResponse.getBody().getMessage();

    }


}
